package com.project.frame.common.model;

import lombok.Data;

import java.io.Serializable;

/**
 * desc
 *
 * @author lw007
 * @date 2021/12/22
 */
@Data
public class BaseResp implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 请求成功
     */
    public static int RC_OK = 0;
    /**
     * 请求失败
     */
    public static int RC_NOT = 1;

    //访问无权限，或者登录已过期
    public static int AUTH_NOT = 2;
    /**
     * 应答返回码
     */
    private int code = RC_OK;

    /**
     * 应答返回消息
     */
    private String msg;

    /**
     * 跳转url
     */
    private String url = "";

    private int count;

    private boolean success = false;// 是否成功

    private Object data;

    public BaseResp() {
        this.code = BaseResp.RC_OK;
        this.msg = "请求成功";
        this.success = true;
    }

    public BaseResp(Object data){
        this.code = BaseResp.RC_OK;
        this.msg = "请求成功";
        this.success = true;
        this.data = data;
    }

    public BaseResp(int code, String msg) {
        if(code==BaseResp.RC_OK){
            this.success = true;
        }else{
            this.success = false;
        }
        this.code = code;
        this.msg = msg;
    }

    public static BaseResp renderFail(String msg){
        BaseResp resp = new BaseResp();
        resp.setSuccess(false);
        resp.setMsg(msg);
        resp.setCode(BaseResp.RC_NOT);
        return resp;
    }

    public static BaseResp renderFail(int code,String msg){
        BaseResp resp = new BaseResp();
        resp.setSuccess(false);
        resp.setMsg(msg);
        resp.setCode(code);
        return resp;
    }

    public static BaseResp renderSuccess(Object data){
        BaseResp resp = new BaseResp();
        resp.setSuccess(true);
        resp.setMsg("");
        resp.setData(data);
        resp.setCode(RC_OK);
        return resp;
    }

}
